package cn.wolfcode.luowowo.website.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.Region;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IRegionService;
import cn.wolfcode.luowowo.hotel.domain.HotelTag;
import cn.wolfcode.luowowo.hotel.domain.HotelTagDetail;
import cn.wolfcode.luowowo.hotel.domain.SpecialHotel;
import cn.wolfcode.luowowo.hotel.domain.SpecialHotelDetail;
import cn.wolfcode.luowowo.hotel.service.IHotelTagService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("hotel")
public class HotelController {

    @Reference
    private IDestinationService destinationService;

    @Reference
    private IHotelTagService hotelTagService;

    @RequestMapping("/hotel")
    public String hotel(Model model){

        //查询国内的信息
        List<Destination> dest = destinationService.getDestByRegionId(-1L);
        //dest
        model.addAttribute("dest",dest);
        //查询亚洲的信息
        List<Destination> list = new ArrayList<>();
        List<Destination> Asian1 = destinationService.getDestByRegionId(2L);
        List<Destination> Asian2 = destinationService.getDestByRegionId(3L);
        List<Destination> Asian3 = destinationService.getDestByRegionId(4L);
        Asian1.forEach(item->{
            list.add(item);
        });
        Asian2.forEach(item->{
            list.add(item);
        });
        Asian3.forEach(item->{
            list.add(item);
        });
        //Asian
        model.addAttribute("Asian",list);

        //欧美
        List<Destination> EA = destinationService.getDestByRegionId(5L);
        model.addAttribute("EA",EA);
        //澳非
        List<Destination> AA = destinationService.getDestByRegionId(6L);
        model.addAttribute("AA",AA);
        //hotelTags
        //查询主题住宿
        List<HotelTag> hotelTags = hotelTagService.all();
        model.addAttribute("hotelTags",hotelTags);

        //hotelCity
        List<SpecialHotel> hotelCitys = hotelTagService.selectAllHotelCity();
        model.addAttribute("hotelCity",hotelCitys);
        return "hotel/hotel";
    }

    @RequestMapping("/theme")
    public String theme(Model model,long id){
        //url
        //name
        //img
        //shortName
        //type
        List<HotelTagDetail> hotelTagDetails = hotelTagService.selectThemeDetail(id);
        model.addAttribute("list",hotelTagDetails);
        return "hotel/hotelTpl";
    }

    @RequestMapping("/theme1")
    public String theme1(Model model,long id){

        List<SpecialHotelDetail> list = hotelTagService.gainAllSpecialHotelDetail(id);
        //hotelScore
        model.addAttribute("hotelScore",list);
        return "hotel/hotelTpl1";
    }

    @RequestMapping("/reservation/{id}/{name}")
    public String reservation(Model model,@PathVariable("id") long cityId,
                                    @PathVariable("name") String cityName){

        List<SpecialHotelDetail> list = hotelTagService.gainAllSpecialHotelDetailByCityId(cityId);

        //共享title
        SpecialHotelDetail detail = list.get(0);
        model.addAttribute("strategy",detail.getStrategy());
        model.addAttribute("title",detail.getTitle());
        //hotel
        model.addAttribute("hotel",list);
        //name
        model.addAttribute("name",cityName);

        return "hotel/dingjiudian";
    }
    @RequestMapping("/h")
    public String h(Model model,String checkIn,String checkOut,String destId,String name,String people){


//        model.addAttribute("hotel",list);
        List<SpecialHotelDetail> list = hotelTagService.gainAllSpecialHotelDetailByDestId(destId);

        //共享title
        SpecialHotelDetail detail = list.get(0);
        model.addAttribute("name",name);
        model.addAttribute("strategy",detail.getStrategy());
        model.addAttribute("people",people.substring(9,17));
        model.addAttribute("title",detail.getTitle());
        model.addAttribute("checkIn",checkIn);
        model.addAttribute("checkOut",checkOut);
        model.addAttribute("hotel",list);

        return "hotel/dingjiudian";
    }

}
